import http from '../http'
import qs from 'qs'
import { request, requestOnline, ResponseCode, moment } from '../baseUrl'

/**
 *  @param request 请求地址 例如：http://197.82.15.15:8088/request/...
 *  @param '/testIp'代表vue-cil中config，index.js中配置的代理
 */

/**
 * @func 活动列表
 * @param {列表对象: record}
 */
const qcjApiAct = `/act`
export async function getQcjApiAct() {
  try {
    const response = await http.get(`${requestOnline}${qcjApiAct}`)
    if (ResponseCode.success !== response.data.code) {
      const message = (typeof response.data.msg === 'string' && response.data.msg) || 'error'
      throw new Error(message)
    }
    return [null, response.data.data]
  } catch (error) {
    return [(typeof error.message === 'string' && error.message) || 'error', null]
  }
}

/**
 * @func 活动列表-查询
 * @param {列表对象: record}
 */
const actSelect = `/act/select`
export async function getActSelect(activityName) {
  try {
    const response = await http.get(`${requestOnline}${actSelect}`, { activityName })
    if (ResponseCode.success !== response.data.code) {
      const message = (typeof response.data.msg === 'string' && response.data.msg) || 'error'
      throw new Error(message)
    }
    return [null, response.data.data]
  } catch (error) {
    return [(typeof error.message === 'string' && error.message) || 'error', null]
  }
}

/**
 * @func 活动列表
 * @param {列表对象: record}
 */
const slotNoShow = `/slot/noShow`
export async function getSlotNoShow() {
  try {
    const response = await http.get(`${requestOnline}${slotNoShow}`)
    if (ResponseCode.success !== response.data.code) {
      const message = (typeof response.data.msg === 'string' && response.data.msg) || 'error'
      throw new Error(message)
    }
    return [null, response.data.data]
  } catch (error) {
    return [(typeof error.message === 'string' && error.message) || 'error', null]
  }
}
